package spw.main;

import org.apache.log4j.Logger;
import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

import spw.log4j.Log4jLogger;
import spw.scheduler.TestJob;

public class Main {
	static Logger log = Logger.getLogger(Log4jLogger.class.getName());
	static int INTERVALINMINUTES=2;
	public static void main(String[] args) {
		log.warn("Init scheduled job");
		try {
			//specify the job's details
			JobDetail job = JobBuilder.newJob(TestJob.class)
					.withIdentity("testJob")
					.build();

			//specify the running period of the job
			Trigger trigger = TriggerBuilder.newTrigger()
					.withSchedule(SimpleScheduleBuilder.simpleSchedule()
							.withIntervalInMinutes(INTERVALINMINUTES)
							.repeatForever())
							.build();

			//schedule the job
			SchedulerFactory schFactory = new StdSchedulerFactory();
			Scheduler sch = schFactory.getScheduler();
			sch.start();
			sch.scheduleJob(job, trigger);
		} catch (SchedulerException e) {
			log.error(e.getMessage());
		}
	}
}